package com.qcby.controller;

import com.qcby.entity.*;
import com.qcby.service.MomentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/Moments")
public class MomentsController {

    @Autowired
    private MomentsService momentsService;

    @PostMapping("/showUserInfoByUserId")
    @ResponseBody
    public Result<User> showUserInfoByUserId(int userId){
        return momentsService.showUserInfoByUserId(userId);
    }

    @PostMapping("/showAllCheckinsByPage")
    @ResponseBody
    public Result<List<UserCheckin>> showAllCheckinsByPage(int pageSize){
        return momentsService.showAllCheckinsByPage(pageSize);
    }

    @PostMapping("/getCommentsByCheckinId")
    @ResponseBody
    public Result<List<Review>> getCommentsByCheckinId(int checkinId){
//        System.out.println(checkingsService.getCommentsByCheckinId(checkinId));
        return momentsService.getCommentsByCheckinId(checkinId);
    }

    @PostMapping("/getChildrenCommentsByParentId")
    @ResponseBody
    public Result<List<Review>> getChildrenCommentsByParentId(int parentId){
//        System.out.println(checkingsService.getChildrenCommentsByParentId(parentId));
        return momentsService.getChildrenCommentsByParentId(parentId);
    }

    @PostMapping("/addComment")
    @ResponseBody
    public Result<Integer> addComment(int checkinId, int userId, String content){
//        System.out.println("checkinId = " + checkinId);
//        System.out.println("userId = " + userId);
//        System.out.println("content = " + content);
        return momentsService.addComment(checkinId, userId,content);
    }

    @PostMapping("/replyComment")
    @ResponseBody
    public Result<Integer> replyComment(int checkinId, int userId, String content, int parentId){
        return momentsService.replyComment(checkinId, userId, content, parentId);
    }

    /**
     * 在朋友圈创建打卡时需要先选择打卡的店铺
     * 选择打卡店铺之前需要根据输入进行模糊查询
     * 最后选择店铺
     *
     * @param shopName 模糊查询的输入
     * @return 所有店铺名称中带有传参的店铺全部信息
     */
    @PostMapping("/fuzzyQueryShop")
    @ResponseBody
    public Result<List<Shop>> fuzzyQueryShop(String shopName){
        return momentsService.fuzzyQueryShop(shopName);
    }

    @PostMapping("/publishMoment")
    @ResponseBody
    public Result<Integer> publishMoment(String context,
                                         String imgsUrls,
                                         int userId,
                                         int shopId){
        System.out.println("context = " + context);
        System.out.println("imgsUrls = " + imgsUrls);
        System.out.println("userId = " + userId);
        System.out.println("shopId = " + shopId);
        return momentsService.publishMoment(context, imgsUrls, userId, shopId);
    }

}
